package edu.ccut.saturn.studio.menuitem.model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import edu.ccut.saturn.studio.core.search.SaturnFileSearcher.SearchResult;

public abstract class SearchResultParse {
	
	public static List<String> parseSearchResult(List<SearchResult> searchResutls) {
		List<String> results = new ArrayList<String>();

		for (SearchResult searchResult : searchResutls) {
			String fileName = searchResult
					.getFile().getPath()
					.replace(File.separator,
							"/"); //$NON-NLS-1$
			String bundleName = searchResult
					.getBundleName();

			int index = fileName
					.indexOf(bundleName);

			String name = fileName
					.substring(index
							+ bundleName
									.length()
							+ 1);
			name = name.substring(name
					.indexOf("/")); //$NON-NLS-1$
			
			String separator = "";
			if (name.endsWith(".action")) {
				separator = "::";
			}
			String result = "/" + bundleName + separator + name; //$NON-NLS-1$ //$NON-NLS-2$
			
			results.add(result);
		}
		
		return results;
	}
}
